﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A5Lib
{
    [Serializable]
    public class Schedule
    {
        public Schedule()
        {
            Dates = new List<DateTimePair>();
        }
        public List<DateTimePair> Dates { get; set; }

        /// <summary>
        /// Adds a datetime pair to the schedule.
        /// </summary>
        /// <param name="d1">The first time(must be before d2)</param>
        /// <param name="d2">The second time(must be after d1)</param>
        /// <returns>Returns False if d1.TimeOfDay is greater than or equal to d2.TimeOfDay
        /// Returns False if there is any overlap with another DateTimePair on the TimeOfDay component</returns>
        public bool addDateTimePair(DateTime d1, DateTime d2)
        {
            //Check that d1<d2
            DateTimePair dtp = DateTimePair.CreateDateTimePair(d1, d2);
            if (dtp == null) return false;

            for (int i = 0; i < Dates.Count; i++)
            {
                //Check if d1 is < otherdate.d2, then d2 is also before otherdate.d1.
                if (d1.TimeOfDay <= Dates[i].d2.TimeOfDay && d2.TimeOfDay >= Dates[i].d1.TimeOfDay) return false;
            }
            
            Dates.Add(dtp);
            return true;
        }
    }
}
